<template>
	<zh-app style="background-color: #FFFFFF;font-family: '阿里巴巴普惠体'">
		<zh-navbar title="报名学校选择" color="#85a5ff" linear="right"/>
		<!-- 筛选结果列表 -->
		<z-paging
			ref="paging"
			:fixed="false"
			height="95vh"
			@query="onQueryList"
			v-model="data.schoolList"
			:show-scrollbar="false"
		>
			<template v-slot:empty>
				<zh-result
					:showBtn="false"
					title="未搜索到学校信息"
					subTitle="请重新输入名称搜索"
				></zh-result>
			</template>
			<template v-slot:top>
				<zh-sheet :padding="[0,0]">
				 	<zh-input
				 		:height="80" 
				 		v-model="data.searchText"
				 		placeholder="可输入学校名称搜索" 
				 		placeholderStyle="text-align: center;" 
				 		 :transprent="false"
				 		showClear
				 	/>
				</zh-sheet>       
			</template>
			<z-paging-cell
				v-for="(item, index) in data.schoolList"
				:key="item.schoolId"
			>
				<schoolInfo :school="item" :studentEnrollPreId="data.studentEnrollPreId">	</schoolInfo>
			</z-paging-cell>
			<template v-slot:bottom>
				<zlb-footer></zlb-footer>
			</template>
			
		</z-paging>
	</zh-app>
</template>

<script lang="ts" setup>
	import {reactive,watch,ref} from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	import schoolInfo from './components/schoolInfo.vue';
	
	let paging =ref();
	const data=reactive({
		// 搜索关键字
		searchText: '',
		//学校列表
		schoolList:[] as Array<any>,
		canSearch:false,
		schoolCategory:'',
		schoolNature:'',
		studentEnrollPreId:''
	})
	// 初始化
	onLoad((options: any) => {
		if(options.schoolCategory){
			data.schoolCategory=options.schoolCategory
		}
		if(options.schoolNature){
			data.schoolNature=options.schoolNature
		}
		if(options.studentEnrollPreId){
			data.studentEnrollPreId=options.studentEnrollPreId
		}
	})
	const onQueryList = (pageNo :number, pageSize:number) => {
		//获取学校列表
		let params :any={}
		params.schoolName=data.searchText
		params.pageNum = pageNo
		params.pageSize = pageSize
		if(data.schoolCategory){
			params.schoolCategory=data.schoolCategory
		}else{
			params.schoolCategoryList=['2','3']
		}
		if(data.schoolNature){
			params.schoolNature=data.schoolNature
		}else{
			params.schoolNature='0'
		}
		
		$api.common.send.post("eduschool0011",params).then((res:any)=>{
			paging.value?.complete(res.result.list || [])
		}).catch(() => {
			paging.value?.complete(false)
		})
	}
	//名称搜索输入
	watch(
	  () => data.searchText,
	  () => {
	    data.canSearch=true
		onSearch()
	  },
	  { deep: true }
	);
	//关闭筛选器的时候触发搜索
	function onSearch() {
		if(data.canSearch){
			uni.$tm.u.debounce(() => paging.value?.reload(), 500)
		}
	}
</script>

<style lang="scss" scoped></style>